﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ScoringClient
{
    class Utilities
    {
        ///  <summary>
        ///  生成随机码
        ///  </summary>
        ///  <param  name="length">随机码个数</param>
        ///  <returns></returns>
        public static string CreateRandomCode(int length)
        {
            int rand;
            char code;
            string randomcode = String.Empty;

            //生成一定长度的验证码
            Random random = new Random(Guid.NewGuid().GetHashCode());
            for (int i = 0; i < length; i++)
            {
                rand = random.Next();

                if (rand % 3 == 0)
                {
                    code = (char)('a' + (char)(rand % 26));
                }
                else
                {
                    code = (char)('0' + (char)(rand % 10));
                }

                if (code == 'o' || code == '0')
                {
                    i--;
                    continue;
                }
                randomcode += code.ToString();
            }
            return randomcode;
        }
    }
}
